package com.example.administrator.myapplication.util;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

/**
 * Created by Administrator on 2020/12/10.
 */

public class DB {
    //用户登录时，根据用户输入的姓名学号查询数据库是否存在
    //select * from account where username="" and student-id=""
    private Context context;

    public  DB(Context context) {
        this.context=context;
    }
    public boolean loginSelect(String username,String student_id){
        Myhepler myhepler=new Myhepler(context);//实例化
        SQLiteDatabase db=myhepler.getReadableDatabase();
        Cursor cursor=db.rawQuery("select * from account where username=? and student_id=?",new String[]{username,student_id});
        if (cursor.getCount()!=0){
            return true;
        }else {
            return false;
        }

    }
//注册
// insert into account(username,student_id)values(?,?)
    public boolean signInsert(String username,String student_id){
        Myhepler myHepler=new Myhepler(context);
        SQLiteDatabase db=myHepler.getWritableDatabase();
        db.execSQL("insert into account(username,student_id) values(?,?)",new Object[]{username,student_id});
        return  true;
    }
}
